package com.baidu.project15.chart31;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;

public class Gj19JavaIterator {
    List<Gj19Student> slist=null;
    public Gj19JavaIterator(){
        Gj19Student[] stu=new Gj19Student[5];
        slist=new ArrayList<Gj19Student>();
        stu[0]=new Gj19Student("张三", 32);
        stu[1]=new Gj19Student("李四", 25);
        stu[2]=new Gj19Student("王五", 21);
        stu[3]=new Gj19Student("赵六", 38);
        stu[4]=new Gj19Student("周七", 26);
        for(int i=0;i<5;i++){
            slist.add(stu[i]);
        }
    }
    public void display(){
        Iterator<Gj19Student> t=slist.iterator();
        System.out.println("遍历获得的原始数据：");
        while(t.hasNext()){
            Gj19Student student=t.next();
            System.out.println("姓名："+student.getName()+"今年"+student.getAge()+"岁");
        }
        Collections.sort(slist);
        Iterator<Gj19Student> it=slist.iterator();
        System.out.println("========================================");
        System.out.println("按年龄从大到小排序：");
        while(it.hasNext()){
            Gj19Student student=it.next();
            System.out.println("姓名："+student.getName()+"今年"+student.getAge()+"岁");
        }
    }

}